-module(init_mnesia).


-export([start/0]).

-include("agent.hrl").


get_nodes()->
	[node()].

start()->
	case 	mnesia:create_schema(get_nodes()) of
		{error , Reason } ->
			io:format("create schema error, Reason:~p~n" , [Reason]);
		ok ->
		case  mnesia:start() of
			 {error ,Reason } ->
			io:format("start  error, Reason:~p~n" , [Reason]);
			ok ->
                                 {atomic, ok} = mnesia:create_table(httpd_proc , 
                                        [{attributes,record_info(fields,httpd_proc)},{disc_copies , get_nodes()} ]),
				 {atomic, ok} = mnesia:create_table(app_term_runtime , 
				        [{attributes,record_info(fields,app_term_runtime)},{disc_copies , get_nodes()} ]),
 			         {atomic, ok} = mnesia:create_table(app_total_runtime , 
 			                [{attributes,record_info(fields,app_total_runtime)},{disc_copies , get_nodes()} ]),
 				 {atomic , ok} = mnesia:create_table(agent_state, 
 				        [{attributes, record_info(fields, agent_state)}, {disc_copies, get_nodes()}]),
				 {atomic, ok} = mnesia:create_table(app,
				        [{attributes, record_info(fields,app)},{disc_copies,get_nodes()}]),
		
				{atomic, ok} = mnesia:create_table(agent_instance,
					[{attributes, record_info(fields,instance_runtime)},{disc_copies,get_nodes()}])	
		 end 
	end.



